#include "randomtestadventurer.h"
int numTreasure(struct gameState* state){
    int player = whoseTurn(state);
    int results = 0;
    for(int i = 0; i < state->handCount[player];i++){
        if(state->hand[player][i] == gold || state->hand[player][i] == silver || state->hand[player][i] == copper){
            results++;
        }
    }
    return results;
}
/**
 int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus)
 */
void testAdventurer(struct gameState* state){

    int preHandTreasure = numTreasure(state);
    int numErrors = 0;
    int player = whoseTurn(state);
    int preCount = state->handCount[player];
    int position = rand()%state->handCount[player];
    state->hand[player][position]=adventurer;
    cardEffect(adventurer,0,0,0,state,position,0);
    if(preHandTreasure>=2){
        if(state->handCount[player]!=preCount+2){
            printf("Failed to draw 2 treasure cards correctly, number of cards in hand is: %i\n",state->handCount[player]);
            numErrors++;
        }
        else{
            if(numTreasure(state)!=preHandTreasure-2){
                printf("Failed to decrement our treasure count correctly number of treasure cards in hand: %i\n",numTreasure(state));
                numErrors++;
            }
            else{
                printf("no errors in card numbers changing at least\n");
            }
        }
    }
    else{
        if(state->handCount[player]!=preCount+preHandTreasure){
            printf("Failed to draw %i treasure cards correctly, number of cards in hand is: %i\n",preHandTreasure,state->handCount[player]);
            numErrors++;
        }
        else{
            if(numTreasure(state)!=numTreasure(state)-preHandTreasure){
                printf("Failed to decrement our treasure count correctly number of treasure cards in hand: %i\n",numTreasure(state));
                numErrors++;
            }
            else{
                printf("no errors in card numbers changing at least\n");
            }
        }
    }
    printf("Number of errors during run of testAdventurer() %i\n",numErrors);
}

int main(int argc, char** argv){
    int cards[10] = {adventurer, council_room, feast, gardens, mine,
        remodel, smithy, village, baron, great_hall};
    
    struct gameState* game =newGame();
    int initialized = initializeGame(2,cards,42,game);
    if(initialized!=-1){
        int toPlay = rand()%2;
        if(toPlay%2 == 0){
            for(int p = 0; p < rand()%256;p++){
                    for(int i = 0; i < rand()%game->handCount[whoseTurn(game)];i++){
                        discardCard(i,whoseTurn(game),game,0);
                        testAdventurer(game);
                    }
            }
        }
        else{
            endTurn(game);
                for(int p = 0; p < rand()%256;p++){
                    for(int i = 0; i < rand()%game->handCount[whoseTurn(game)];i++){
                        discardCard(i,whoseTurn(game),game,0);
                        testAdventurer(game);
                    }
                }
            }
        
    }
    return 0;
    
}
